home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 3: CDPD 3
/
Almathera Ten on Ten - Disc 3: CDPD3.iso
/
fish
/
676-700
/
681
/
term
/
source.lha
/
ScreenPanel.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-09
|
18KB
|
679 lines
/*
** $Id: ScreenPanel.c,v 1.5 92/05/01 12:52:58 olsen Sta Locker: olsen $
** $Revision: 1.5 $
** $Date: 92/05/01 12:52:58 $
**
** Editing panel for screen configuration
**
** Copyright © 1990-1992 by Olaf `Olsen' Barthel & MXM
** All Rights Reserved
*/
#include "termGlobal.h"
enum { GAD_MODES,GAD_MODE,GAD_NEWMODE,GAD_PALETTE,GAD_RED,GAD_GREEN,GAD_BLUE,GAD_MAKEPUBLIC,
GAD_SHANGHAI,GAD_USE,GAD_CANCEL };
#define WIDTH 451
#define HEIGHT 175
WORD WindowWidth = WIDTH,
WindowHeight = HEIGHT;
/* The names of the 16 display modes. */
STATIC UBYTE *ModeNames[16] =
{
"Hires",
"Hires interlaced",
"Super hires",
"Super hires interlaced",
"Productivity",
"Productivity interlaced",
"PAL hires",
"PAL hires interlaced",
"PAL super hires",
"PAL super hires interlaced",
"NTSC hires",
"NTSC hires interlaced",
"NTSC super hires",
"NTSC super hires interlaced",
"A2024 10 Hz",
"A2024 15 Hz"
};
STATIC struct Node ModeNodes[16];
STATIC struct List ModeList;
STATIC BYTE ModeLimited;
/* ModeOkay(ULONG ID):
*
* Checks whether a display mode ID will do for deep
* screen bitmaps.
*/
BYTE __regargs
ModeOkay(ULONG ID)
{
struct DimensionInfo DimensionInfo;
if(GetDisplayInfoData(NULL,(APTR)&DimensionInfo,sizeof(struct DimensionInfo),DTAG_DIMS,ID))
{
if(DimensionInfo . MaxDepth >= 4)
return(TRUE);
}
return(FALSE);
}
#ifdef ASLSM_FilterFunc
STATIC UBYTE *
CreateNewMode(ULONG Mode)
{
STATIC UBYTE Buffer[DISPLAYNAMELEN];
struct NameInfo NameInfo;
if(!GetDisplayInfoData(NULL,(APTR)&NameInfo,sizeof(struct NameInfo),DTAG_NAME,Mode))
{
struct DimensionInfo DimensionInfo;
if(!GetDisplayInfoData(NULL,(APTR)&DimensionInfo,sizeof(struct DimensionInfo),DTAG_NAME,Mode))
strcpy(Buffer,LocaleString(MSG_SCREENPANEL_UNKNOWN_TXT));
else
{
UBYTE *MonitorName;
switch(Mode & MONITOR_ID_MASK)
{
case NTSC_MONITOR_ID: MonitorName = "NTSC: ";
break;
case PAL_MONITOR_ID: MonitorName = "PAL: ";
break;
case VGA_MONITOR_ID: MonitorName = "VGA: ";
break;
case A2024_MONITOR_ID: MonitorName = "A2024: ";
break;
default: MonitorName = "";
break;
}
SPrintf(Buffer,"%s%ld × %ld",MonitorName,DimensionInfo . TxtOScan . MaxX - DimensionInfo . TxtOScan . MinX + 1,DimensionInfo . TxtOScan . MaxY - DimensionInfo . TxtOScan . MinY + 1);
}
}
else
strcpy(Buffer,NameInfo . Name);
return(Buffer);
}
STATIC LONG __saveds __asm
ModeFilter(register __a1 ULONG ID)
{
if(ModeLimited)
return((LONG)ModeOkay(ID));
else
return(TRUE);
}
STATIC BYTE __regargs
SelectDisplayMode(struct Window *Window,ULONG *Mode)
{
struct ScreenModeRequester *Request;
struct Hook FilterHook;
BYTE Result = FALSE;
FilterHook . h_Entry = (APTR)ModeFilter;
FilterHook . h_SubEntry = NULL;
FilterHook . h_Data = NULL;
if(Request = (struct ScreenModeRequester *)AllocAslRequestTags(ASL_ScreenModeRequest,
ASLSM_Window, Window,
ASLSM_InitialDisplayID, *Mode,
ASLSM_PropertyFlags, DIPF_IS_WB,
ASLSM_FilterFunc, &FilterHook,
ASLSM_PrivateIDCMP, TRUE,
TAG_DONE))
{
if(AslRequestTags(Request,TAG_DONE))
{
*Mode = Request -> sm_DisplayID;
Result = TRUE;
}
FreeAslRequest(Request);
}
return(Result);
}
#endif /* ASLSM_FilterFunc */
STATIC struct Gadget *
CreateAllGadgets(LONG *ModeNumber,LONG *NumModes,struct Configuration *LocalConfig,struct Gadget **GadgetArray,struct Gadget **GadgetList,APTR VisualInfo,UWORD TopEdge,BYTE WrongMode)
{
struct Gadget *Gadget;
struct NewGadget NewGadget;
UWORD Counter = 0;
BYTE Count = 0,i,Mode;
WindowWidth = WIDTH;
WindowHeight = HEIGHT;
memset(&NewGadget,0,sizeof(struct NewGadget));
if(Gadget = CreateContext(GadgetList))
{
WORD NewTop;
if(LocalConfig -> ColourMode == COLOUR_EIGHT || LocalConfig -> ColourMode == COLOUR_SIXTEEN)
ModeLimited = TRUE;
else
ModeLimited = FALSE;
#ifdef ASLSM_FilterFunc
if(AslBase -> lib_Version < 38)
#endif /* ASLSM_FilterFunc */
{
memset(&ModeList,0,sizeof(struct List));
memset(ModeNodes,0,sizeof(struct Node) * 16);
NewList(&ModeList);
*NumModes = 0;
/* This loop runs all possible display modes through `ModeNotAvailable'
* to determine which resolutions are not supported by the current
* monitor spec.
*/
for(i = 0 ; i < 16 ; i++)
{
if(!ModeNotAvailable(ModeID[i]))
{
if(ModeLimited)
{
if(ModeOkay(ModeID[i]))
{
if(LocalConfig -> DisplayMode == ModeID[i])
Mode = Count;
ModeNodes[Count] . ln_Name = ModeNames[i];
ModeNodes[Count] . ln_Type = i;
AddTail(&ModeList,&ModeNodes[Count++]);
}
}
else
{
if(LocalConfig -> DisplayMode == ModeID[i])
Mode = Count;
ModeNodes[Count] . ln_Name = ModeNames[i];
ModeNodes[Count] . ln_Type = i;
AddTail(&ModeList,&ModeNodes[Count++]);
}
}
else
{
if(i == Mode)
Mode = 0;
}
}
*NumModes = Count;
*ModeNumber = Mode;
NewGadget . ng_Width = 241;
NewGadget . ng_Height = 60;
NewGadget . ng_GadgetText = LocaleString(MSG_SCREENPANEL_AVAILABLE_DISPLAY_MODES_GAD);
NewGadget . ng_TextAttr = &DefaultFont;
NewGadget . ng_VisualInfo = VisualInfo;
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_Flags = PLACETEXT_LEFT;
NewGadget . ng_LeftEdge = (strlen(NewGadget . ng_GadgetText) + 2) * 8 + 1;
NewGadget . ng_TopEdge = 1 + TopEdge;
GadgetArray[Counter++] = Gadget = CreateGadget(LISTVIEW_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
GTLV_Labels, &ModeList,
GTLV_ShowSelected, NULL,
GTLV_Selected, Mode,
GTLV_Top, Mode,
TAG_DONE);
if(!Gadget)
return(NULL);
NewTop = Gadget -> TopEdge + Gadget -> Height + 13;
}
#ifdef ASLSM_FilterFunc
else
{
WindowWidth -= (3 * 8);
WindowHeight -= 25;
Counter = GAD_MODE;
NewGadget . ng_Width = 240;
NewGadget . ng_Height = 12;
NewGadget . ng_GadgetText = LocaleString(MSG_SCREENPANEL_CURRENT_DISPLAY_MODE_GAD);
NewGadget . ng_TextAttr = &DefaultFont;
NewGadget . ng_VisualInfo = VisualInfo;
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_Flags = PLACETEXT_LEFT;
NewGadget . ng_LeftEdge = 22 * 8 + 1;
NewGadget . ng_TopEdge = 1 + TopEdge;
if(ModeNotAvailable(LocalConfig -> DisplayMode))
LocalConfig -> DisplayMode = HIRES_KEY;
GadgetArray[Counter++] = Gadget = CreateGadget(TEXT_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
GTTX_Text, CreateNewMode(LocalConfig -> DisplayMode),
GTTX_Border, TRUE,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_GLOBAL_SELECT_NEW_DISPLAY_MODE_TXT);
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_Flags = 0;
NewGadget . ng_TopEdge = NewGadget . ng_Height + NewGadget . ng_TopEdge + 1;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
TAG_DONE);
NewTop = NewGadget . ng_Height + NewGadget . ng_TopEdge + 1;
}
#endif /* ASLSM_FilterFunc */
Counter = GAD_PALETTE;
NewGadget . ng_GadgetText = LocaleString(MSG_SCREENPANEL_EDIT_SCREEN_PALETTE_GAD);
NewGadget . ng_Width = 240;
NewGadget . ng_Height = 30;
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = NewTop;
NewGadget . ng_Flags = PLACETEXT_LEFT;
GadgetArray[Counter++] = Gadget = CreateGadget(PALETTE_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
GTPA_Depth, Config . ColourMode == COLOUR_EIGHT ? 3 : Screen -> RastPort . BitMap -> Depth,
GTPA_Color, 0,
GTPA_IndicatorWidth, NewGadget . ng_Width / (1 << 2),
GTPA_IndicatorHeight, NewGadget . ng_Height,
GA_Disabled, WrongMode,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_SCREENPANEL_RED_GAD);
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = NewGadget . ng_TopEdge + NewGadget . ng_Height + 1;
NewGadget . ng_Height = 10;
NewGadget . ng_Width = 240;
GadgetArray[Counter++] = Gadget = CreateGadget(SLIDER_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
GTSL_Min, 0,
GTSL_Max, 15,
GTSL_Level, 0,
GTSL_LevelFormat, "%2ld",
GTSL_MaxLevelLen, 2,
GA_Disabled, WrongMode,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_SCREENPANEL_GREEN_GAD);
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = NewGadget . ng_TopEdge + NewGadget . ng_Height + 1;
GadgetArray[Counter++] = Gadget = CreateGadget(SLIDER_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
GTSL_Min, 0,
GTSL_Max, 15,
GTSL_Level, 0,
GTSL_LevelFormat, "%2ld",
GTSL_MaxLevelLen, 2,
GA_Disabled, WrongMode,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_SCREENPANEL_BLUE_GAD);
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = NewGadget . ng_TopEdge + NewGadget . ng_Height + 1;
GadgetArray[Counter++] = Gadget = CreateGadget(SLIDER_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
GTSL_Min, 0,
GTSL_Max, 15,
GTSL_Level, 0,
GTSL_LevelFormat, "%2ld",
GTSL_MaxLevelLen, 2,
GA_Disabled, WrongMode,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_SCREENPANEL_MAKE_SCREEN_PUBLIC_GAD);
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = NewGadget . ng_TopEdge + NewGadget . ng_Height + 1;
NewGadget . ng_Width = 26;
NewGadget . ng_Height = 11;
GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
GTCB_Checked, LocalConfig -> MakeScreenPublic,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_SCREENPANEL_SHANGHAI_WINDOWS_GAD);
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = NewGadget . ng_TopEdge + NewGadget . ng_Height + 1;
GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
GTCB_Checked, LocalConfig -> ShanghaiWindows,
GA_Disabled, LocalConfig -> MakeScreenPublic ? FALSE : TRUE,
TAG_DONE);
NewGadget . ng_Width = 88; /* NEW 52 */
NewGadget . ng_Height = 12;
NewGadget . ng_GadgetText = LocaleString(MSG_GLOBAL_USE_GAD);
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_Flags = 0;
NewGadget . ng_LeftEdge = 10;
NewGadget . ng_TopEdge = WindowHeight - 3 - NewGadget . ng_Height;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_GLOBAL_CANCEL_GAD);
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_LeftEdge = WindowWidth - 10 - NewGadget . ng_Width;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
TAG_DONE);
}
return(Gadget);
}
BYTE
ScreenPanel(struct Configuration *MyConfig)
{
struct Window *PanelWindow;
struct Gadget *GadgetList = NULL;
struct Gadget *GadgetArray[GAD_CANCEL + 1];
LONG ModeNumber,NumModes;
BYTE WrongMode;
WORD i;
if(Config . ColourMode == MyConfig -> ColourMode)
WrongMode = FALSE;
else
WrongMode = TRUE;
CopyMem(MyConfig,&PrivateConfig,sizeof(struct Configuration));
if(CreateAllGadgets(&ModeNumber,&NumModes,MyConfig,&GadgetArray[0],&GadgetList,VisualInfo,Screen -> WBorTop + Screen -> Font -> ta_YSize + 1,WrongMode))
{
if(PanelWindow = OpenWindowTags(NULL,
WA_Left, (Screen -> Width - WindowWidth) >> 1,
WA_Top, (Screen -> Height - WindowHeight) >> 1,
WA_Width, WindowWidth,
WA_Height, WindowHeight,
WA_Activate, TRUE,
WA_DragBar, TRUE,
WA_DepthGadget, TRUE,
WA_RMBTrap, TRUE,
WA_DepthGadget, TRUE,
WA_CloseGadget, TRUE,
WA_CustomScreen,Screen,
WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_VANILLAKEY | SLIDERIDCMP | CHECKBOXIDCMP | LISTVIEWIDCMP | PALETTEIDCMP | BUTTONIDCMP,
WA_Title, LocaleString(MSG_SCREENPANEL_SCREEN_PREFERENCES_TXT),
TAG_DONE))
{
struct IntuiMessage *Massage;
ULONG Class,Code;
struct Gadget *Gadget;
BYTE Terminated = FALSE;
struct Node *SomeNode;
LONG ColourNumber = 0;
BYTE Red,Green,Blue;
PushWindow(PanelWindow);
Red = (MyConfig -> Colours[ColourNumber] >> 8) & 0xF;
Green = (MyConfig -> Colours[ColourNumber] >> 4) & 0xF;
Blue = (MyConfig -> Colours[ColourNumber] ) & 0xF;
AddGList(PanelWindow,GadgetList,(UWORD)-1,(UWORD)-1,NULL);
RefreshGList(GadgetList,PanelWindow,NULL,(UWORD)-1);
GT_RefreshWindow(PanelWindow,NULL);
GT_SetGadgetAttrs(GadgetArray[GAD_RED],PanelWindow,NULL,
GTSL_Level,Red,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_GREEN],PanelWindow,NULL,
GTSL_Level,Green,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_BLUE],PanelWindow,NULL,
GTSL_Level,Blue,
TAG_DONE);
if(!WrongMode)
LoadRGB4(VPort,&MyConfig -> Colours[0],16);
while(!Terminated)
{
WaitPort(PanelWindow -> UserPort);
while(!Terminated && (Massage = (struct IntuiMessage *)GT_GetIMsg(PanelWindow -> UserPort)))
{
Class = Massage -> Class;
Code = Massage -> Code;
Gadget = (struct Gadget *)Massage -> IAddress;
GT_ReplyIMsg(Massage);
if(Class == IDCMP_VANILLAKEY)
KeySelect(GadgetArray,GAD_CANCEL,Code,PanelWindow,&Gadget,&Class,&Code);
if(Class == IDCMP_CLOSEWINDOW)
Terminated = TRUE;
if(Class == IDCMP_MOUSEMOVE)
{
switch(Gadget -> GadgetID)
{
case GAD_RED: Red = Code;
MyConfig -> Colours[ColourNumber] = (Red << 8) | (Green << 4) | (Blue);
LoadRGB4(VPort,MyConfig -> Colours,1 << (Screen -> RastPort . BitMap -> Depth));
break;
case GAD_GREEN: Green = Code;
MyConfig -> Colours[ColourNumber] = (Red << 8) | (Green << 4) | (Blue);
LoadRGB4(VPort,MyConfig -> Colours,1 << (Screen -> RastPort . BitMap -> Depth));
break;
case GAD_BLUE: Blue = Code;
MyConfig -> Colours[ColourNumber] = (Red << 8) | (Green << 4) | (Blue);
LoadRGB4(VPort,MyConfig -> Colours,1 << (Screen -> RastPort . BitMap -> Depth));
break;
default: break;
}
}
if(Class == IDCMP_GADGETUP)
{
switch(Gadget -> GadgetID)
{
case GAD_RED: Red = Code;
MyConfig -> Colours[ColourNumber] = (Red << 8) | (Green << 4) | (Blue);
LoadRGB4(VPort,MyConfig -> Colours,1 << (Screen -> RastPort . BitMap -> Depth));
break;
case GAD_GREEN: Green = Code;
MyConfig -> Colours[ColourNumber] = (Red << 8) | (Green << 4) | (Blue);
LoadRGB4(VPort,MyConfig -> Colours,1 << (Screen -> RastPort . BitMap -> Depth));
break;
case GAD_BLUE: Blue = Code;
MyConfig -> Colours[ColourNumber] = (Red << 8) | (Green << 4) | (Blue);
LoadRGB4(VPort,MyConfig -> Colours,1 << (Screen -> RastPort . BitMap -> Depth));
break;
case GAD_MAKEPUBLIC: if(!GT_CHECKED(Gadget))
{
GT_SetGadgetAttrs(GadgetArray[GAD_SHANGHAI],PanelWindow,NULL,
GTCB_Checked, FALSE,
GA_Disabled, TRUE,
TAG_DONE);
}
else
{
GT_SetGadgetAttrs(GadgetArray[GAD_SHANGHAI],PanelWindow,NULL,
GA_Disabled, FALSE,
TAG_DONE);
}
break;
case GAD_MODES: if(SomeNode = GetListNode(Code,&ModeList))
{
MyConfig -> DisplayMode = ModeID[SomeNode -> ln_Type];
ModeNumber = SomeNode -> ln_Type;
}
break;
#ifdef ASLSM_FilterFunc
case GAD_NEWMODE: BlockWindow(PanelWindow);
if(SelectDisplayMode(PanelWindow,&MyConfig -> DisplayMode))
{
GT_SetGadgetAttrs(GadgetArray[GAD_MODE],PanelWindow,NULL,
GTTX_Text, CreateNewMode(MyConfig -> DisplayMode),
TAG_DONE);
}
ReleaseWindow(PanelWindow);
break;
#endif /* ASLSM_FilterFunc */
case GAD_PALETTE: ColourNumber = Code;
SetPalette: Red = (MyConfig -> Colours[ColourNumber] >> 8) & 0xF;
Green = (MyConfig -> Colours[ColourNumber] >> 4) & 0xF;
Blue = (MyConfig -> Colours[ColourNumber] ) & 0xF;
GT_SetGadgetAttrs(GadgetArray[GAD_RED],PanelWindow,NULL,
GTSL_Level,Red,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_GREEN],PanelWindow,NULL,
GTSL_Level,Green,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_BLUE],PanelWindow,NULL,
GTSL_Level,Blue,
TAG_DONE);
break;
case GAD_USE: Terminated = TRUE;
if(MyConfig -> ColourMode == COLOUR_EIGHT)
{
for(i = 0 ; i < 8 ; i++)
MyConfig -> Colours[i + 8] = MyConfig -> Colours[i];
}
if(MyConfig == &Config)
{
CopyMem(&MyConfig -> Colours[0],&BlinkColours[0],sizeof(UWORD) * 16);
switch(MyConfig -> ColourMode)
{
case COLOUR_EIGHT: for(i = 0 ; i < 8 ; i++)
BlinkColours[i + 8] = BlinkColours[0];
break;
case COLOUR_SIXTEEN: break;
case COLOUR_AMIGA:
default: BlinkColours[3] = BlinkColours[0];
break;
}
}
MyConfig -> MakeScreenPublic = GT_CHECKED(GadgetArray[GAD_MAKEPUBLIC]);
MyConfig -> ShanghaiWindows = GT_CHECKED(GadgetArray[GAD_SHANGHAI]);
break;
case GAD_CANCEL: Terminated = TRUE;
CopyMem(&PrivateConfig,MyConfig,sizeof(struct Configuration));
if(!memcmp(&Config,MyConfig,sizeof(struct Configuration)))
LoadRGB4(VPort,&MyConfig -> Colours[0],16);
else
LoadRGB4(VPort,&Config . Colours[0],16);
break;
default: break;
}
}
}
}
RemoveGList(PanelWindow,GadgetList,(UWORD)-1);
PopWindow();
CloseWindow(PanelWindow);
}
}
FreeGadgets(GadgetList);
if(PrivateConfig . DisplayMode != MyConfig -> DisplayMode)
return(TRUE);
else
return(FALSE);
}